<template>
  <div>
    <el-form :model="queryParams" ref="queryForm" size="mini" :inline="true" v-show="showSearch" label-width="68px"
      @submit.native.prevent>
      <el-form-item label="统计日期" prop="statisticsTime">
        <el-date-picker clearable v-model="statisticsTime" type="month" value-format="yyyy-MM" placeholder="请选择产生时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button v-hasPermi="['cld:confirm:export']" icon="el-icon-download" plain size="mini" type="primary"
          @click="handleExport">列表导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="CldPayDetailsList" border @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center">
      </el-table-column>
      <el-table-column label="日期" align="center">
        <template slot-scope="scope">
          <span>{{ `${scope.row.year}-${scope.row.month}` }}</span>
        </template>
      </el-table-column>
      <el-table-column label="项目区域" align="center">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cld_project_region" :value="scope.row.projectRegion" />
        </template>
      </el-table-column>
      <el-table-column label="应发薪酬" align="center" prop="basicSalary">
        <template slot-scope="scope">
          {{ toMoney(scope.row.postWages + scope.row.jobCategory) }}
        </template>
      </el-table-column>
      <el-table-column label="实发薪酬" align="center" prop="inSalary">
        <template slot-scope="scope">
          {{ toMoney(scope.row.inSalary) }}
        </template>
      </el-table-column>
      <el-table-column label="工资差额" align="center" prop="basicSalary">
        <template slot-scope="scope">
          {{ toMoney((scope.row.postWages + scope.row.jobCategory) - (scope.row.inSalary)) }}
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleDetails(scope.row)"
            v-hasPermi="['cld:CldPayDetails:query']">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import { selectRealTimeSalaryGrouping } from "@/api/cld/CldPayDetails";

export default {
  name: "CldPayDetails",
  dicts: ['cld_project_region'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 薪酬管理表格数据
      CldPayDetailsList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        year: new Date().getFullYear(),
        month: (new Date().getMonth() + 1),
        params: {
          groupByType: 1
        }
      },
      statisticsTime: new Date().getFullYear() + '-' + (new Date().getMonth() + 1),
      // 详情弹框
      multipleSelection: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询薪酬管理列表 */
    getList() {
      this.loading = true;
      selectRealTimeSalaryGrouping(this.queryParams).then(response => {
        this.CldPayDetailsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.year = this.parseTime(this.statisticsTime, '{y}');
      this.queryParams.month = this.parseTime(this.statisticsTime, '{m}');
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.year = new Date().getFullYear();
      this.queryParams.month = (new Date().getMonth() + 1);
      this.statisticsTime = new Date().getFullYear() + '-' + (new Date().getMonth() + 1);
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 详情查看
    handleDetails(row) {
      this.$router.push("/CldPayDetails/realTime/regionDetails/" + row.projectRegion);
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
      console.log(this.multipleSelection, '==')
    },
    // 导出
    handleExport() {
      if (this.multipleSelection.length === 0) {
        this.$message({
          message: '请选择需要导出的区域',
          type: 'warning'
        });
        return
      }

      let arr = []
      this.multipleSelection.forEach(item => {
        arr.push(item.projectRegion)
      })

      this.download('cld/confirm/export', {
        year: this.queryParams.year,
        month: this.queryParams.month,
        projectRegion: arr.join(',')
      }, `工资导出.xlsx`)
    }
  }
};
</script>
